<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <style>
        body {
            font-size: 20px;
        }

        header {
            background-color: #1bbc9b;
        }

        #main {
            -webkit-box-flex: 1;
            -webkit-flex: 1;
            background-color: #fff;
        }

        section {
            background-color: #fff;
        }

        h1 {
            height: 2.5rem;
            line-height: 2.5rem;
            color: #fff;
            font-size: 20px;
            text-align: center;
        }

        .back {
            position: absolute;
            left: 0px;
            bottom: 0px;
            width: 2.5rem;
            height: 2.5rem;
            background: url(../image/header/back.png) center center no-repeat;
            background-size: 25px auto;
        }

        .userinfo {
            width: 96%;
            height: 76px;
            margin: 5px auto;
            border-bottom: solid 1px #fafafa;
        }

        .userinfo .yyuan {
            float: left;
            width: 60px;
            height: 60px;
            border-radius: 50%;
            background-color: #FFA500;
            text-align: center;
            line-height: 63px;
            font-size: .8rem;
            color: #fff;
            margin: 7px auto;
        }

        .userinfo .name {
            float: left;
            font-size: 1.2rem;
            line-height: 80px;
            margin-left: 10px;
        }

        .remark {
            width: 96%;
            height: 50px;
            margin: 5px auto;
            color: #7d8082;
            font-size: .9rem;
            line-height: 50px;
            text-align: center;
        }

        .kuang {
            width: 98%;
            overflow: hidden;
            margin: 0px auto;
            text-align: center;
            border-top: solid #f0eff4 10px;
            border-bottom: solid #f0eff4 10px;
        }

        .kuang .title {
            font-size: 1rem;
            line-height: 2rem;
            height: 2rem;
        }

        .kuang .rows {
            overflow: hidden;
            border-bottom: solid #e0e0e0 1px;
            padding: 5px 0;
        }

        .kuang .rows .left {
            width: 80%;
            float: left;
            font-size: .7rem;
            text-align: left;
            padding-top: 4px;
        }

        .kuang .rows .right {
            width: 19%;
            float: right;
            font-size: 1rem;
        }

        .kuang .rows .right .inputc {
            width: 20px;
            height: 20px;
        }

        .kuang .rows .left .inputt {
            display: inline;
            border: solid 1px #ccc;
        }

        .aui-btn {
            font-size: 1rem;
            height: 2rem;
            line-height: 2rem;
            min-width: 5rem;
        }
        .qiandaorow{
              width: 96%;
              height: 150px;
              margin: 30px auto 5px auto;
              text-align: center;
          }
          .qiandaorow .blueyuan{
              width: 120px;
              height: 120px;
              border-radius:50%;
              background: linear-gradient(#67c0ff, #3196fa); /* 标准的语法 */
              text-align: center;
              line-height: 1.4rem;
              font-size:.9rem;
              color: #fff;
              margin: 0px auto;
              padding-top: 45px;
          }
    </style>
</head>

<body>
    <header id="header">
        <div id="bikeclose" class="back event-back" tapmode onclick="api.closeWin({name:'xjx'});"></div>
        <h1 id="pagetitle"></h1>
    </header>

    <section tyle="width:92%; margin:8px auto 0px auto; ">

        <div class="qiandaorow">
              <div class="blueyuan" tapmode onclick="readText();">
                    点击巡检
                  
                  
              </div>
        </div>
    </section>

    <div id="main">
    </div>


</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/bike.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript">
    var demo = null;
    apiready = function() {
        var userinfo = $api.getStorage('userinfo');

        demo = api.require('nfc');
        readingAvailable();
        initPageConfig();
    };

    function readingAvailable() {
        demo.readingAvailable(function(ret, err) {
            // alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
        });
    }

    function initPageConfig() {
        demo.initPageConfig({
            isDebug: true, //开启时，不支持nfc的手机可以打开界面看UI效果
            backgroundColor: '#ffffff', //页面背景色
            title: {
                text: '请读卡', //标题
                color: '#ffffff', //标题字体颜色
                background: '#336699', //标题栏背景色
                layoutHeight: 45 //标题栏高度
            },
            center: {
                logo: 'widget://image/timg-2.gif', //图片logo文件路径 支持fs:// widget://
                text: '请将NFC标签或者贴纸靠近手机背面', //文字说明
                color: '#00EE00', //文字说明字体颜色
            }
        }, function(ret, err) {
            // alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
        });
    }

    function readText() {

        demo.readText(function(ret, err) {
            if (ret) {
                // alert(ret.tagId);
                // $api.val($api.byId('xjdposition'),JSON.stringify(ret.result));
                // $api.val($api.byId('nfcid'),ret.tagId);
                save(ret.tagId);
            } else {
                alert(JSON.stringify(err));
            }
            
        });
    }

    function save(tagId){
        var userinfo = $api.getStorage('userinfo');
        var uid = userinfo.uid;
        //alert(usernametext);
        if(tagId=="")
        {
            alert('NFC卡编码不能为空');
        }
        else
        {
                var apipath = $api.getStorage('apipath');
                var apiurl = apipath+"/Xjxtapi/addxj";
                api.ajax({
                    url: apiurl,
                    method: 'post',
                    timeout: 5,
                    dataType: 'json',
                    returnAll: false,
                    data:{
                        values: {
                            apiuser:getConfigValue('apiuser'),
                            apipass:getConfigValue('apipass'),
                            uid: uid,
                            nfcid: tagId
                        }
                    }
                }, function(ret, err) {
                    //alert(JSON.stringify(ret));
                    alert(ret.remsg);
                    if(ret.renum=='1')
                    {
                        api.closeWin({name:'xjd'});
                    }
                });
            
        }

     
    }
</script>

</html>
